export const useCountDown = (duration: number) => {
    const countDown = ref(duration)
    const interId=ref(0)
    const isRunning = ref(false)
    const start = () => {
        interId.value=setInterval(() => {
            countDown.value--
            if (countDown.value <= 0) {
                clearInterval(interId.value)
                isRunning.value = false
            }
        }, 1000)
        isRunning.value = true
    }
    const restart = () => {
        countDown.value = duration
        start()
    }
    const stop = () => {
        clearInterval(interId.value)
        isRunning.value = false
    }
    onUnmounted(() => { clearInterval(interId.value);isRunning.value=false })
    return { countDown, start, restart, stop,isRunning }
}